package com.pro.controller;

import com.pro.pojo.JsUiserAuthority;
import com.pro.pojo.JsonData;
import com.pro.service.JsUiserAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author 祖铭泽
 * @Date 2021/12/1/0001
 * @description 权限用户表 控制层
 */
@Controller
@RequestMapping(value = "/jsUiserAuthority")
public class JsUiserAuthorityController {
    @Autowired
    private JsUiserAuthorityService jsUiserAuthorityService;
    //查询后台用户所拥有的权限
    @RequestMapping(value = "/getUserAuthority")
    @ResponseBody
    public JsonData getUserAuthority(Integer userId){
        List<JsUiserAuthority> userAuthority = jsUiserAuthorityService.getUserAuthority(userId);
        return userAuthority != null ? JsonData.buildSuccess(userAuthority) : JsonData.buildError("服务器出错了");
    }

    //修改用户所拥有的权限
    @RequestMapping(value = "/updateUserAuthority")
    @ResponseBody
    public JsonData updateUserAuthority(JsUiserAuthority jsUiserAuthority){
        boolean deleteUserAuthority = jsUiserAuthorityService.deleteUserAuthority(jsUiserAuthority.getUserId());
        boolean addUserAuthority = jsUiserAuthorityService.addUserAuthority(jsUiserAuthority);
        return deleteUserAuthority && addUserAuthority ? JsonData.buildSuccess(jsUiserAuthority) : JsonData.buildError("服务器出错了");
    }
}
